package tools;

public class BoolVector extends Vector<Boolean> {

	public BoolVector(int dim) {
		super(dim);
		list = new Boolean[dim];
		mem.addDoubleSize(dim);
	}

	@Override
	public Vector<Boolean> copy() {
		Vector<Boolean> ret = new BoolVector(dim);
		for(int i = 0; i < dim; i++){
			ret.set(i, list[i]);
		}
		return ret;
	}

	@Override
	public boolean isBigger(Vector<Boolean> other, int i) {
		return sumElem(i) <= ((BoolVector)other).sumElem(i);
	}

	@Override
	public boolean isSmaller(Vector<Boolean> other, int i) {
		return sumElem(i) <= ((BoolVector)other).sumElem(i);
	}

	@Override
	public Boolean sum(int i) {
		return sum(0, i);
	}

	@Override
	public Boolean sum(int i, int j) {
		boolean ret = true;
		
		for(int k = i; k < j; k++) ret &= list[k].booleanValue();
		
		return new Boolean(ret);
	}
	
	public int sumElem(int i) {
		return sumElem(0, i);
	}
	
	public int sumElem(int i, int j) {
		int ret = 0;
		
		for(int k = i; k < j; k++) if(list[k].booleanValue()) ret++;
		
		return ret;
	}

	@Override
	protected Boolean define0() {
		return new Boolean(false);
	}

}
